<?php
/**
 * Created by PhpStorm.
 * User: icemoon
 * Date: 2021-08-09
 * Time: 09:01
 */

namespace App\Http\Actions;


use App\Exceptions\BlogHasExistException;
use App\Models\Blog;

class CreateBlog implements IAction
{
	public function execute(array $data)
	{

		if( Blog::where('user_id',$data['user_id'])->exists()){
			throw new BlogHasExistException('blog has been exist!');
		}
		$blog = new Blog();
		$blog->user_id = $data['user_id'];
		$blog->blog_name = $data['blog_name'];
		$blog->save();
		return $blog;
	}
}